# models.py

from sqlalchemy import Column, Date, String, Integer, Float, DECIMAL, Boolean, Text, ForeignKey
from sqlalchemy.orm import declarative_base, relationship

Base = declarative_base()

class StockList(Base):
    __tablename__ = 'taomu_stock_list'

    code = Column(String(10), primary_key=True)  # 如 sh.600000
    tradeStatus = Column(String(20))
    code_name = Column(String(100))

    def __repr__(self):
        return f"<StockList(code={self.code}, name={self.code_name})>"


class StockHistory(Base):
    __tablename__ = 'taomu_stock_history'

    date = Column(Date, primary_key=True)
    code = Column(String(10), primary_key=True)

    open = Column(DECIMAL(10, 2))
    high = Column(DECIMAL(10, 2))
    low = Column(DECIMAL(10, 2))
    close = Column(DECIMAL(10, 2))
    preclose = Column(DECIMAL(10, 2))
    volume = Column(Float)
    amount = Column(DECIMAL(15, 2))
    adjustflag = Column(String(20))
    turn = Column(DECIMAL(5, 2))
    tradestatus = Column(String(20))
    pctChg = Column(DECIMAL(5, 2))
    isST = Column(String(5))

    obv = Column(Float)
    M5 = Column(Float)
    M10 = Column(Float)
    M20 = Column(Float)
    M30 = Column(Float)
    M50 = Column(Float)
    M60 = Column(Float)
    EMA5 = Column(Float)
    EMA10 = Column(Float)
    EMA20 = Column(Float)
    BBI = Column(Float)

    boll_upper = Column(Float)
    boll_middle = Column(Float)
    boll_lower = Column(Float)

    macd_dif = Column(Float)
    macd_dea = Column(Float)
    macd = Column(Float)

    rsi6 = Column(Float)
    rsi12 = Column(Float)

    k = Column(Float)
    d = Column(Float)
    j = Column(Float)

    def __repr__(self):
        return f"<StockHistory(date={self.date}, code={self.code}, close={self.close})>"